package interfaces;

import gestores.GestorInterfaces;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import cliente.Cliente;

import dados.Jogador;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class EcranGuest extends VBox{
	
	private Stage stage;
	private Cliente cliente;
	private GestorInterfaces interfaces;
	private final String link = "http://mystock.uni.me/";
	
	public EcranGuest(Stage stage, Cliente cliente, GestorInterfaces interfaces) {
		this.stage = stage;
		this.cliente = cliente;
		this.interfaces = interfaces;
		criarJanelaGuest();
	}
	
	public void criarJanelaGuest() {
		FXMLLoader guest = new FXMLLoader(getClass().getResource("ModoGuest.fxml"));
		guest.setRoot(this);
		guest.setController(this);
		try {
			guest.load();
		} catch (IOException exception) {
			throw new RuntimeException(exception);
		}
	}
	
	@FXML
	public void novaConta(ActionEvent event) {
		try {
			URI url = new URI(link);
			java.awt.Desktop.getDesktop().browse(url);
		} catch (IOException e1) {
			e1.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
	}
	
	@FXML
	public void entrarJogoComoGuest(ActionEvent event) {

		cliente.setJogador(new Jogador("Guest"));
		cliente.setGuest(true);
		System.out.println(cliente.getJogador());

		stage.close();
		interfaces.getStageActual().close();
		interfaces.ecranInicial(new Stage());
	}
}
